package com.ssy.lingxi.platform.template.service.controller.adorn;

import com.ssy.lingxi.common.constant.basic.UserLoginSourceEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.template.service.entity.adorn.Advert;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.AdvertDTO;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.CategoryAdornDTO;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.SaveAdvertDTO;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.SaveTemplateAdornDTO;
import com.ssy.lingxi.platform.template.service.model.dto.common.MemberIdDTO;
import com.ssy.lingxi.platform.template.service.model.dto.web.RecommendDTO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.BrandVO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.CategoryAdornVO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.CategoryVO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.GoodsVO;
import com.ssy.lingxi.platform.template.service.service.adorn.WebChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 模板装修 - WEB渠道装修
 * @author fhj
 * @version 2.0.0
 * @date 2020/12/25
 */
@Api(tags = "模板装修 - WEB渠道装修")
@RestController
@RequestMapping("/template/adorn/webChannel")
public class WebChannelController extends BaseController {

    @Resource
    private WebChannelService webChannelService;
    @Resource
    private HttpServletRequest request;

    @ApiOperation(value = "获取所有一级会员品类")
    @GetMapping("/findAllFirstCategory")
    public Wrapper<List<CategoryVO>> findAllFirstCategory(@Valid MemberIdDTO dto) {
        return webChannelService.findAllFirstCategory(dto, getHeadersShopId());
    }

    @ApiOperation(value = "会员品类的装修内容")
    @GetMapping("/memberCategoryAdorn")
    public Wrapper<CategoryAdornVO> memberCategoryAdorn(@Valid CategoryAdornDTO dto, HttpServletRequest request) {
        return webChannelService.memberCategoryAdorn(dto, isLogin() && getSysUser(request).getLoginSource().equals(UserLoginSourceEnum.BUSINESS_WEB.getCode()) ? getSysUser(request) : null);
    }

    @ApiOperation(value = "根据类型获取广告")
    @GetMapping("/findAdvertsByType")
    public Wrapper<List<Advert>> findAdvertsByType(@Valid AdvertDTO dto) {
        return webChannelService.findAdvertsByType(dto);
    }

    @ApiOperation(value = "获取商品列表")
    @GetMapping("/findGoodsList")
    public Wrapper<PageData<GoodsVO>> findGoodsList(@Valid RecommendDTO dto, HttpServletRequest request) {
        return webChannelService.findGoodsList(dto, getSysUser(request));
    }

    @ApiOperation(value = "获取品类列表")
    @GetMapping("/findCategoryList")
    public Wrapper<CategoryAdornVO> findCategoryList(@Valid RecommendDTO dto, HttpServletRequest request) {
        return webChannelService.findCategoryList(dto, getSysUser(request));
    }

    @ApiOperation(value = "获取品牌列表（下拉框）")
    @GetMapping("/findBrandList")
    public Wrapper<PageData<BrandVO>> findBrandList(@Valid RecommendDTO dto, HttpServletRequest request) {
        return webChannelService.findBrandList(dto, getSysUser(request));
    }

    @ApiOperation(value = "保存广告")
    @PostMapping("/saveAdvert")
    public Wrapper<Void> saveAdvert(@RequestBody @Valid SaveAdvertDTO dto, HttpServletRequest request) {
        return webChannelService.saveAdvert(dto, getSysUser(request));
    }

    @ApiOperation(value = "保存商品")
    @PostMapping("/saveGoods")
    public Wrapper<Void> saveGoods(@RequestBody @Valid SaveTemplateAdornDTO dto, HttpServletRequest request) {
        return webChannelService.saveGoods(dto, getSysUser(request));
    }

    @ApiOperation(value = "保存品类")
    @PostMapping("/saveCategory")
    public Wrapper<Void> saveCategory(@RequestBody @Valid SaveTemplateAdornDTO dto, HttpServletRequest request) {
        return webChannelService.saveCategory(dto, getSysUser(request));
    }
}
